import { api, ApiResponse } from './client'
import { User } from '@/types/sheet'

// 认证相关接口
export interface LoginCredentials {
  email: string
  password: string
}

export interface RegisterCredentials {
  name: string
  email: string
  password: string
}

export interface AuthResult {
  success: boolean
  user?: User
  token?: string
  error?: string
}

// 认证相关 API
export const authApi = {
  // 用户登录
  login: (credentials: LoginCredentials): Promise<ApiResponse<{ user: User; token: string }>> =>
    api.post('/auth/login', credentials),

  // 用户注册
  register: (credentials: RegisterCredentials): Promise<ApiResponse<{ user: User; token: string }>> =>
    api.post('/auth/register', credentials),

  // 验证 token
  verifyToken: (): Promise<ApiResponse<{ user: User }>> =>
    api.get('/auth/verify'),

  // 刷新 token
  refreshToken: (): Promise<ApiResponse<{ token: string }>> =>
    api.post('/auth/refresh'),

  // 用户登出
  logout: (): Promise<ApiResponse<void>> =>
    api.post('/auth/logout'),

  // 更改密码
  changePassword: (data: { oldPassword: string; newPassword: string }): Promise<ApiResponse<void>> =>
    api.put('/auth/change-password', data),
}

export default authApi
